#Title[New Familiar]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{

let angle=GetArgument[0];
let color=GetArgument[1];
color=(color-1)*40;
let grow=0;

let radius=0;
let move=0;
let fade=0.5;

let damagerate=10;
let usespell=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEdeath=("script\SoundEffects\enemydeath1.wav");
let SEshotm3=("script\SoundEffects\shotm3.wav");

let GRfamiliar=("\script\Images\OtherEffects\Chips.png");

@Initialize{
	LoadGraphic("\script\Images\OtherEffects\Chips.png");

	LoadSE("script\SoundEffects\enemydeath1.wav");
	LoadSE("script\SoundEffects\shotm3.wav");

	SetScore(100);
	SetLife(50);
	SetDamageRate(10,10);
	MagicCircle(false);
}
	
@MainLoop{

if(fade>=1){ SetCollisionA(GetX,GetY,grow*18); }
if(fade>=1){ SetCollisionB(GetX,GetY,grow*18); }
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=1.5; }
SetDamageRate(damagerate,damagerate);

let shotcolor=0;
if(color==1){ shotcolor=49; }
if(color==2){ shotcolor=50; }
if(color==3){ shotcolor=51; }
if(color==4){ shotcolor=53; }
if(color==5){ shotcolor=56; }
if(color==6){ shotcolor=57; }
if(color==7){ shotcolor=59; }

if(GetCommonData("Difficulty")==1){
SetShotDirectionType(PLAYER);
	if((time+0)%400==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,0.75,145,0); }
	if((time+100)%400==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,0.75,157,0); }
	if((time+200)%400==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,0.75,145,0); }
	if((time+300)%400==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,0.75,157,0); }
SetShotDirectionType(ABSOLUTE);
	if(time%100==0 && time>=240){ PlaySE(SEshotm3); }
} //Easy

//================================================================================================

if(GetCommonData("Difficulty")==2){
SetShotDirectionType(PLAYER);
	if((time+0)%320==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,1,145,0); }
	if((time+80)%320==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,1,157,0); }
	if((time+160)%320==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,1,145,0); }
	if((time+240)%320==0 && time>=240){ CreateShot02(GetX,GetY,0,0,0.08,1,157,0); }
SetShotDirectionType(ABSOLUTE);
	if(time%80==0 && time>=240){ PlaySE(SEshotm3); }
} //Normal

//================================================================================================

if(GetCommonData("Difficulty")==3){
	if((time+0)%220==0 && time>=200){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+175,0.05,0.8,145,0);
	}
	if((time+55)%220==0 && time>=200){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+180,0.05,0.8,157,0);
	}
	if((time+110)%220==0 && time>=200){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+185,0.05,0.8,145,0);
	}
	if((time+165)%220==0 && time>=200){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+180,0.05,0.8,157,0);
	}
	if(time%55==0 && time>=200){ PlaySE(SEshotm3); }
} //Hard

//================================================================================================

if(GetCommonData("Difficulty")==4){
	if((time+0)%220==0 && time>=160){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+170,0.05,1.2,145,0);
	}
	if((time+55)%220==0 && time>=160){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+180,0.05,1.2,157,0);
	}
	if((time+110)%220==0 && time>=160){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+190,0.05,1.2,145,0);
	}
	if((time+165)%220==0 && time>=160){
	CreateShot02(GetX,GetY,0,GetCommonData("Spin")/3+angle+180,0.05,1.2,157,0);
	}
	if(time%55==0 && time>=160){ PlaySE(SEshotm3); }
} //Lunatic


let distance=1-GetCommonData("SpinSpeed")*0.03;
SetX(cx+(radius*distance)*cos(GetCommonData("Spin")/3+angle));
SetY(cy+(radius*distance)*sin(GetCommonData("Spin")/3+angle));
radius+=5.6*cos(move);

if(move<90){ move+=2; }
if(grow<1){ grow+=0.1; }
if(time>=180 && fade<1){ fade+=1/100; }
if(fade>1){ fade=1; }

time++;
frame++;

}

@DrawLoop{
	SetGraphicScale(grow,grow);
	SetTexture(GRfamiliar);
	SetGraphicAngle(0,0,time*5);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetAlpha(255*fade);
	SetGraphicRect(0+color,0,40+color,40);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){ PlaySE(SEdeath); }
}

}